/*----------------------------------------------------------------------------
Owner(s): Shane Whitfield
$Copyright: $
$Id: 

Purpose  : Controls game flow
----------------------------------------------------------------------------*/

#pragma once

#include "texture.h"
#include "bbmath.h"

/*--------------------------------------------------------------------------*/
//  Class CGoHealStation declaration.
class CMapLocation
{
public:

				CMapLocation(const char* i_levelFileName, const Vector2f& i_pos);
	void		Update();
	void		Render();
	bool		IsPointerWithin(const Vector2f& i_pos);
	void		SetUnlocked(bool i_is) {
					m_isUnlocked = i_is; }
	bool		IsUnlocked() const {
					return m_isUnlocked; } 
	void		SetPos(const Vector2f& i_pos) {
					m_worldMat.SetPos(i_pos); }
	const char*	GetLevelName() const {
					return m_level;}
	void		SetLevelName(const char* i_levelFileName) {
					strcpy(m_level, i_levelFileName); }

private:

	const CTexture*	s_targetTexture;
	bool			m_isUnlocked;
	Transform2D		m_worldMat;
	float			m_rotation;
	char			m_level[100];
};

/*--------------------------------------------------------------------------*/
//  Class CMap declaration.
class CMap
{

public:

				CMap(const char* i_fileName);
				~CMap();
	void		Render();
	void		Update();
	bool		IsPointWithin(const Vector2f& i_touchPos, const Vector2f& i_worldTouchPos) const;
	static void	SetFileLoader(bool (*systemFileLoader)(const char* i_filename, CMap* io_map));
	void		UnlockNextLevel();
	void		On_LocationLoad(const char* i_levelFileName, float i_x, float i_y, bool unlocked);
	void		On_ImageLoad(const char* i_imageFileName);
	
	void		ScaleLeft();
	void		ScaleRight();
	
	void		ForceAsPreviousLevel(){
					setState(EState_Previous); }
	void		ForceAsCurrentLevel() {
					setState(EState_Current); }
	void		ForceAsNextLevel() {
					setState(EState_Next); }

private:

	enum EState
	{
		EState_OffScreen,
		EState_Previous,
		EState_Current,
		EState_Next,
		
		EState_ScaleToPrevious,
		EState_ScaleToNext,
		EState_ScaleToOffScreen,
	};
	
	void	setState(EState i_state);

	EState						m_state;
	float						m_tState;
	const CTexture*				m_mapBackGround;
	Transform2D					m_worldMat;
	std::vector<CMapLocation*>	m_mapLocations;
	int							m_lastMapRequestIndex;
	bool						m_unlocked;
	Vector2f					m_min;
	Vector2f					m_max;
};

/*--------------------------------------------------------------------------*/
//  Class CMapMgr declaration.
class CMapMgr : public TSingleton<CMapMgr>, public CSubsystem
{
	typedef CSubsystem super;
	
public:

					CMapMgr();
					~CMapMgr();
	void			RequestMap() {
						m_mapRequested = true; }
	bool			IsMapRequested() const {
						return m_mapRequested; }
	virtual void	OnInit();
	void			Render();
	void			Update();
	void			Activate() {
						setState(EState_Active); m_mapRequested = false; }
	void			UnlockNextLevel();
	bool			HasPreviousMap() const {
						return m_curMapIndex > 0; }
	bool			HasNextMap() const {
						return m_curMapIndex < m_maps.size() - 1; }

private:

	enum EState
	{
		EState_Inactive,
		EState_Active,
	};
	
	void	setCurrentMapIndex(int i_mapIndex);
	void	setState(EState i_state);
	CMap*	getCurMap();

	EState				m_state;
	bool				m_mapRequested;
	std::vector<CMap*>	m_maps;
	int					m_curMapIndex;
	int					m_maxMaps;
	const CTexture*		m_backGround;
	Transform2D			m_worldMat;
};

inline CMapMgr& CMapMgr_GetSingleton() { return CMapMgr::GetSingleton(); }
#define g_mapmgr (CMapMgr_GetSingleton())

/*-----------------------------------EOF!-----------------------------------*/
